#include <stdio.h>

#define LEN 16

typedef struct {
	int data[16];
	int min[16];
	int pos;
} stack_t;

void push(stack_t *s, int data)
{
	s->data[s->pos] = data;
	if (s->pos == 0)
		s->min[s->pos] = data;
	else
		if (data < s->min[s->pos - 1])
			s->min[s->pos] = data;
		else
			s->min[s->pos] = s->min[s->pos - 1];
	s->pos++;
}

int pop(stack_t *s)
{
	return s->data[s->pos--];
}

int min(stack_t *s)
{
	return s->min[s->pos - 1];
}

void print_stack(stack_t *s)
{
	int i;

	for (i = 0; i < s->pos; i++)
		printf("%d ", s->data[i]);
}

void init_stack(stack_t *s)
{
	s->pos = 0;
}

int main()
{
	int data[LEN] = { 5, 3, 2, 4, 1, 8, 9, 6,
			  10, 22, 15, 0, -4, 3, -3, -1};

	int i;
	stack_t s[1];

	for (i = 0; i < LEN; i++) {
		push(s, data[i]);
		print_stack(s);
		printf("\tmin:%d\n", min(s));
	}

	for (i = 0; i < LEN - 1; i++) {
		pop(s);
		print_stack(s);
		printf("\tmin:%d\n", min(s));
	}

	return 0;
}
